Skip to content

Sheetworker Aliases

These are functions that provide K-scaffold aliases for the basic Roll20 sheetworker functions. These functions also provide many additional features on top of the standard Roll20 sheetworkers.

k.generateRowID

member

Alias for generateRowID that adds the new id to the sectionObj. Also allows for creation of custom IDs that conform to the section ID requirements.

  • sections - sectionObj -
    undefined
  • customText - string -

    Custom text to start the ID with. This text should not be longer than the standard repeating section ID format.

  • Returns: string- The created ID

Example

js
k.getAllAttrs({
 callback:(attributes,sections,casc)=>{
   //Create a new row ID
   const rowID = k.generateRowID('repeating_equipment',sections);
   console.log(rowID);// => repeating_equipment_-p8rg908ug0suzz
   //Create a custom row ID
   const customID = k.generateRowID('repeating_equipment',sections,'custom');
   console.log(customID);// => repeating_equipment_-custom98uadj89kj
 }
});
k.getAllAttrs({
 callback:(attributes,sections,casc)=>{
   //Create a new row ID
   const rowID = k.generateRowID('repeating_equipment',sections);
   console.log(rowID);// => repeating_equipment_-p8rg908ug0suzz
   //Create a custom row ID
   const customID = k.generateRowID('repeating_equipment',sections,'custom');
   console.log(customID);// => repeating_equipment_-custom98uadj89kj
 }
});

k.getAllAttrs

function

Alias for getAttrs() and getSectionIDs that combines the actions of both sheetworker functions and converts the default object of attribute values into an attributesProxy. Also gets the details on how to handle all attributes from the master cascades object and.

  • args - Object -
    undefined
  • args.props - Array.<string> -

    Array of attribute names to get the value of. Defaults to baseGet if not passed.

  • sectionDetails - repeatingSectionDetails -

    Array of details about a section to get the IDs for and attributes that need to be gotten.

  • args.callback - function -

    The function to call after the attribute values have been gotten. An attributesProxy is passed to the callback along with a sectionObj and expandedCascade.

Example

js
//Get every K-scaffold linked attribute on the sheet
k.getAllAttrs({
 callback:(attributes,sections,casc)=>{
   //Work with the attributes as you please.
   attributes.some_attribute = 'a value';
   attributes.set();//Apply our change
 }
})
//Get every K-scaffold linked attribute on the sheet
k.getAllAttrs({
 callback:(attributes,sections,casc)=>{
   //Work with the attributes as you please.
   attributes.some_attribute = 'a value';
   attributes.set();//Apply our change
 }
})

k.getAttrs

member

Alias for getAttrs() that converts the default object of attribute values into an attributesProxy and passes that back to the callback function.

  • props - Array.<string> -

    Array of attribute names to get the value of. Defaults to baseGet if not passed.

  • callback - function -

    The function to call after the attribute values have been gotten. An attributesProxy is passed to the callback.

Example

js
//Gets the attributes named in props.
k.getAttrs({
 props:['attribute_1','attribute_2'],
 callback:(attributes)=>{
   //Work with the attributes as you would in a normal getAttrs, or use the superpowers of the K-scaffold attributes object like so:
   attributes.attribute_1 = 'new value';
   attributes.set();
 }
})
//Gets the attributes named in props.
k.getAttrs({
 props:['attribute_1','attribute_2'],
 callback:(attributes)=>{
   //Work with the attributes as you would in a normal getAttrs, or use the superpowers of the K-scaffold attributes object like so:
   attributes.attribute_1 = 'new value';
   attributes.set();
 }
})

k.getSections

function

Alias for getSectionIDs() that allows you to iterate through several functions at once. Also assembles an array of repeating attributes to get.

  • sectionDetails - Array.<object> -

    Array of details about a section to get the IDs for and attributes that need to be gotten.

  • sectionDetails.section - string -

    The full name of the repeating section including the repeating_ prefix.

  • sectionDetails.fields - Array.<string> -

    Array of field names that need to be gotten from the repeating section

  • callback - function -

    The function to call once all IDs have been gotten and the array of repating attributes to get has been assembled. The callback is passed the array of repating attributes to get and a sectionObj.

Example

js
// Get some section details
const sectionDetails = {
 {section:'repeating_equipment',fields:['name','weight','cost']},
 {section:'repeating_weapon',fields:['name','attack','damage']}
};
k.getSections(sectionDetails,(attributeNames,sections)=>{
 console.log(attributeNames);// => Array containing all row specific attribute names
 console.log(sections);// => Object with arrays containing the row ids. Indexed by section name (e.g. repeating_eqiupment)
})
// Get some section details
const sectionDetails = {
 {section:'repeating_equipment',fields:['name','weight','cost']},
 {section:'repeating_weapon',fields:['name','attack','damage']}
};
k.getSections(sectionDetails,(attributeNames,sections)=>{
 console.log(attributeNames);// => Array containing all row specific attribute names
 console.log(sections);// => Object with arrays containing the row ids. Indexed by section name (e.g. repeating_eqiupment)
})

k.getTranslationByKey

member

An alias for Roll20's getTranslationByKey that also supports data-i18n-vars syntax replacement and returns the translation key if no value is found instead of false.

  • key - string -

    The translation key to look up.

  • variables - Array.<string> -

    An array of variable values to replace variable indexes with.

  • Returns: stringundefined

k.removeRepeatingRow

member

Alias for removeRepeatingRow that also removes the row from the current object of attribute values and array of section IDs to ensure that erroneous updates are not issued.

  • row - string -

    The row id to be removed

  • attributes - attributesProxy -

    The attribute values currently in memory

  • sections - object -

    Object that contains arrays of all the IDs in sections on the sheet indexed by repeating name.

  • Returns: voidundefined

Example

js
//Remove a repeating Row
k.getAllAttrs({
 callback:(attributes,sections)=>{
   const rowID = sections.repeating_equipment[0];
   k.removeRepeatingRow(`repeating_equipment_${rowID}`,attributes,sections);
   console.log(sections.repeating_equipment); // => rowID no longer exists in the array.
   console.log(attributes[`repeating_equipment_${rowID}_name`]); // => undefined
 }
})
//Remove a repeating Row
k.getAllAttrs({
 callback:(attributes,sections)=>{
   const rowID = sections.repeating_equipment[0];
   k.removeRepeatingRow(`repeating_equipment_${rowID}`,attributes,sections);
   console.log(sections.repeating_equipment); // => rowID no longer exists in the array.
   console.log(attributes[`repeating_equipment_${rowID}_name`]); // => undefined
 }
})

k.setAttrs

function

Alias for setAttrs() that sets silently by default.

  • obj - object -

    The object containting attributes to set

  • vocal - boolean -

    Whether to set silently (default value) or not.

  • callback - function -

    The callback function to invoke after the setting has been completed. No arguments are passed to the callback function.

Example

js
//Set some attributes silently
k.setAttrs({attribute_1:'new value'})
//Set some attributes and triggers listeners
k.setAttrs({attribute_1:'new value',true})
//Set some attributes and call a callback function
k.setAttrs({attribute_1:'new value'},null,()=>{
 //Do something after the attribute is set
})
//Set some attributes silently
k.setAttrs({attribute_1:'new value'})
//Set some attributes and triggers listeners
k.setAttrs({attribute_1:'new value',true})
//Set some attributes and call a callback function
k.setAttrs({attribute_1:'new value'},null,()=>{
 //Do something after the attribute is set
})

k.setSectionOrder

member

Alias for setSectionOrder() that allows you to use the section name in either repeating_section or section formats. Note that the Roll20 sheetworker setSectionOrder currently causes some display issues on sheets.

  • section - string -

    The name of the section, with or without repeating_

  • order - Array.<string> -

    Array of ids describing the desired order of the section.

  • Returns: voidundefined

Example

js
//Set the order of a repeating_weapon section
k.setSectionOrder('repeating_equipment',['id1','id2','id3']);
//Can also specify the section name without the repeating_ prefix
k.setSectionOrder('equipment',['id1','id2','id3']);
//Set the order of a repeating_weapon section
k.setSectionOrder('repeating_equipment',['id1','id2','id3']);
//Can also specify the section name without the repeating_ prefix
k.setSectionOrder('equipment',['id1','id2','id3']);

Released under the MIT License